package com.nft.qz.validator.valid;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;

public class IsSexValidator implements ConstraintValidator<IsSex,String> {

    List<String> sexList ;
    @Override
    public void initialize(IsSex constraintAnnotation) {
        sexList = Arrays.asList(constraintAnnotation.value());
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if(CollectionUtils.isEmpty(sexList)) {
            return true;
        }
        return sexList.contains(s);
    }
}
